package com.itheima.sc.web.pms;


import com.itheima.sc.result.Result;
import com.itheima.sc.vo.BrandVo;
import com.itheima.sc.vo.PageResult;
import com.itheima.sc.pojo.pms.Brand;
import com.itheima.sc.service.pms.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("brand")
public class BrandController {
    @Autowired
    private BrandService brandService;

    @PostMapping("create")  //添加品牌
    public Result create(@RequestBody Brand brand){
        brandService.create(brand);
        return Result.success(null);
    }

    @GetMapping("delete/{id}")  //删除单个品牌
    public Result delete(@PathVariable Integer id){
        brandService.deleteById(id);
        return Result.success(null);
    }

    @PostMapping("/delete/batch")  //批量删除品牌
    public Result deleteByIds(@RequestBody List ids){
        brandService.deleteByIds(ids);
        return Result.success(null);
    }

    @GetMapping("list") //根据品牌名称分页获取品牌列表
    public Result<PageResult> listByPage(String keyword,
                                         @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                                         @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){
        PageResult pageResult = brandService.listByPage(keyword,pageNum,pageSize);
        return Result.success(pageResult);
    }

    @GetMapping("listAll")  //获取全部品牌列表
    public Result listAll(){
        List<BrandVo> brandVoList  = brandService.listAll();
        return Result.success(brandVoList);
    }

    //批量更新厂家制造商状态
    @PostMapping("/update/factoryStatus")
    public Result updateFactoryStatus(@RequestParam Integer factoryStatus,
                                      @RequestParam List<Integer> ids){
        brandService.updateFactoryStatus(factoryStatus,ids);
        return Result.success(null);
    }

    //批量更新显示状态
    @PostMapping("/update/showStatus")
    public Result updateShowStatus(@RequestParam Integer showStatus,
                                   @RequestParam List<Integer> ids){
        brandService.updateShowStatus(showStatus,ids);
        return Result.success(null);
    }

    //更新品牌
    @PostMapping("update/{id}")
    public Result updateById(@PathVariable Integer id,
                             @RequestBody Brand brand){
        brandService.updateById(id,brand);
        return Result.success(null);
    }

    //根据编号查询品牌信息
    @GetMapping("{id}")
    public Result getById(@PathVariable Integer id){
        BrandVo brandVo = brandService.getById(id);
        return Result.success(brandVo);
    }










}
